import os

file_dir = r'D:\Desktop\exceltest\部门'
all_files = os.listdir(file_dir)
xlsx_files = list(filter(lambda name: name.endswith('.xlsx'),all_files))
for file_name in xlsx_files:
    xlsx_file_path =rf'{file_dir}\{file_name}'
    if os.path.exists(xlsx_file_path):
        os.remove(xlsx_file_path)


